# coding: utf8

user_id = auth.user.id if auth.user else 0


CITY_SIZE=25
STATE_SIZE=25
newline = '\n'
default_street= T('123 Some Street')
default_city=T('Montréal')
default_province="Québec"
default_country = 'Canada'
default_postal_code= 'H2P 1M5'
default_address = 'street' + newline + default_city + ',' + default_province
default_address_type = 1

db.define_table('address_type',
    Field('name',default=default_address_type,
             label=T("Address Type")),
#    audit_table
    )

db.define_table('address',
    Field('site_member_id', db.auth_user, default=user_id, writable=False),
#    Field('auth_user_id',db.auth_user,writable=False,readable=False),
#    Field('donor_id',db.donor,
#            writable=False,readable=False),
    Field('address_type_id', db.address_type, default=default_address_type, writable=False, readable=False),
    Field('address', "text",
             length=255, default=default_street, 
             label=T("Address")),
    Field('city', length=CITY_SIZE, default=default_city, label=T("City")),
    Field('province', length=STATE_SIZE, default=default_province, 
          label=T("Province/State")),
    Field('postal_code', length=8, default=None, label=T("Postal Code"),
          comment=T("Enter the postal or zip code")),
#    Field('address_display', type='text',default=default_address),
#    audit_table
    )

#db.address.donor_id.requires = IS_IN_DB(db,"donor.id","%(name)s")
db.address.site_member_id.requires = IS_IN_DB(db,"auth_user.id","%(name)s")
db.address.address_type_id.requires = IS_IN_DB(db,"address_type.id","%(name)s")
db.address.address_type_id.requires = IS_IN_DB(db,"address_type.id","%(name)s")
